﻿using System.Reflection;
using WebApplication1.Cmds.Provider;
using WebApplication1.Model;

namespace WebApplication1.Cmds
{
    public class HttpAgentCommand(IServiceProvider sp) : ICommand<string>
    {
        public async Task<string> Execute(HttpCmdArgModel args)
        {
            if (args == null || string.IsNullOrWhiteSpace(args.url)) return string.Empty;
            IProvider<string> provider = sp.GetServices<IProvider<string>>()
                .FirstOrDefault(p => p.GetType().FullName.Contains(args.providerName + "Provider"));
            if (provider != null) return await provider.Execute(args);
            return string.Empty;
        }

    }
}
